<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>Multi-Pie Chart</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1">Multi-Pie Chart</p>
<hr class="separator">
<div class="content">
<img src="images/multipie0.png" width='180' height='160'>&nbsp;&nbsp;<img src="images/multipie1.png" width='180' height='160'>&nbsp;&nbsp;<img src="images/multipie2.png" width='180' height='160'>
<br><br>
This example demonstrates drawing multiple pies with different data and colors. It also demonstrates putting labels on the sectors and using sector borders.<br><br>
<ul><li> The sectors colors are specified using <a href="BaseChart.setColors2.htm">BaseChart.setColors2</a>.<br><br>
<li> The sectors all have white borders set using <a href="PieChart.setLineColor.htm">PieChart.setLineColor</a>. The borders around the perimeters are invisible as they are the same color as the background. The sector borders internal to the pies become the separating lines among sectors.<br><br>
<li> The sector labels are configured with a pale yellow background and black border. This is by getting the <a href="TextBox.htm">TextBox</a> object representing the sector label prototype using <a href="PieChart.setLabelStyle.htm">PieChart.setLabelStyle</a>, and then call its <a href="Box.setBackground.htm">Box.setBackground</a> method.<br><br>
<li> The sector labels are moved inside the pie by using <a href="PieChart.setLabelLayout.htm">PieChart.setLabelLayout</a> with a negative label position.</ul>
</div>
<p class="heading1a">Source Code Listing</p>
<div class="content">
<b>[JSP Version]</b> jspdemo/multipie.jsp
<div class='codeblock'><code class='pre'>&lt;%@page import="ChartDirector.*, java.util.*" %&gt;
&lt;%!
// Function to create the demo charts
void createChart(WebChartViewer viewer, int chartIndex)
{
    // The data for the pie chart
    double[] data0 = {25, 18, 15};
    double[] data1 = {14, 32, 24};
    double[] data2 = {25, 23, 9};

    // The labels for the pie chart
    String[] labels = {"Software", "Hardware", "Services"};

    // Create a PieChart object of size 180 x 160 pixels
    PieChart c = new PieChart(180, 160);

    // Set the center of the pie at (90, 80) and the radius to 60 pixels
    c.setPieSize(90, 80, 60);

    // Set the border color of the sectors to white (ffffff)
    c.setLineColor(0xffffff);

    // Set the background color of the sector label to pale yellow (ffffc0) with a black border
    // (000000)
    c.setLabelStyle().setBackground(0xffffc0, 0x000000);

    // Set the label to be slightly inside the perimeter of the circle
    c.setLabelLayout(Chart.CircleLayout, -10);

    // Set the title, data and colors according to which pie to draw
    if (chartIndex == 0) {
        c.addTitle("Alpha Division", "Arial Bold", 8);
        c.setData(data0, labels);
        int[] colors0 = {0xff3333, 0xff9999, 0xffcccc};
        c.setColors2(Chart.DataColor, colors0);
    } else if (chartIndex == 1) {
        c.addTitle("Beta Division", "Arial Bold", 8);
        c.setData(data1, labels);
        int[] colors1 = {0x33ff33, 0x99ff99, 0xccffcc};
        c.setColors2(Chart.DataColor, colors1);
    } else {
        c.addTitle("Gamma Division", "Arial Bold", 8);
        c.setData(data2, labels);
        int[] colors2 = {0x3333ff, 0x9999ff, 0xccccff};
        c.setColors2(Chart.DataColor, colors2);
    }

    // Output the chart
    viewer.setChart(c, Chart.SVG);

    // Include tool tip for the chart
    viewer.setImageMap(c.getHTMLImageMap("", "", "title='{label}: US${value}M ({percent}%)'"));
}
%&gt;
&lt;%
// This example includes 3 charts
WebChartViewer[] viewers = new WebChartViewer[3];
for (int i = 0; i &lt; viewers.length; ++i) {
    viewers[i] = new WebChartViewer(request, "chart" + i);
    createChart(viewers[i], i);
}
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Multi-Pie Chart&lt;/title&gt;
    &lt;!-- Include ChartDirector Javascript Library to support chart interactions --&gt;
    &lt;script type="text/javascript" src="cdjcv.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body style="margin:5px 0px 0px 5px"&gt;
    &lt;div style="font:bold 18pt verdana;"&gt;
        Multi-Pie Chart
    &lt;/div&gt;
    &lt;hr style="border:solid 1px #000080; background:#000080" /&gt;
    &lt;div style="font:10pt verdana; margin-bottom:1.5em"&gt;
        &lt;a href="viewsource.jsp?file=&lt;%=request.getServletPath()%&gt;"&gt;View Source Code&lt;/a&gt;
    &lt;/div&gt;
    &lt;!-- ****** Here are the chart images ****** --&gt;
    &lt;%
        for (int i = 0; i &lt; viewers.length; ++i) {
            out.write(viewers[i].renderHTML(response));
            out.write(" ");
        }
    %&gt;
&lt;/body&gt;
&lt;/html&gt;</code></div>
</div>
<br><hr class="separator"><div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
